/*
 * @Description: 
 * @Author: Binggan
 * @Date: 2019-09-10 10:53:47
 * @LastEditors: Binggan
 * @LastEditTime: 2020-03-06 12:01:15
 */
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import iView from 'iview';
import '@/assets/css/common.css';
import '@/assets/scss/common.scss';
import 'iview/dist/styles/iview.css';

const isDebug_mode = process.env.NODE_ENV !== 'production';
Vue.config.debug = isDebug_mode;
Vue.config.devtools = isDebug_mode;
Vue.config.productionTip = isDebug_mode;

Vue.use(iView);

//全局引入axios
import axios from './assets/axios/interceptors'
Vue.prototype.$axios=axios;

import "./assets/iconfonts/iconfont.css"

//引入vuex
import store from '@/vuex/store'

import vuescroll from 'vuescroll/dist/vuescroll-native';
Vue.use(vuescroll);


// 全局过滤器
import mFilters from './assets/js/filter'
Object.keys(mFilters).forEach( key =>{
  Vue.filter(key,mFilters[key]);
})

// import {Message} from 'iview';
router.beforeEach((to, from, next) => {
  // 判断要去的路由界面是不是要鉴权
  console.log('luyou'+to.meta.checkLogined)
  console.log(store.state.user)
  if (to.meta.checkLogined) {
    // 查看是否登陆
    if (!store.state.user) {
      // 没登录的做处理      
      iView.Message.error("您未登录，请先登录！");
      next({
        path: '/login',
        query:{redirect:to.fullPath}
      });
    } else {
      // 登陆的根据权限跳
      let roleIndex=to.meta.reqAuth.indexOf(store.state.user.roleId);
      if(roleIndex!=-1){
        next();
      }else{
        next({ path: from.path });
        iView.Message.error("您没有权限进入此页！");
      }
    }
  } else {
    // 不需要鉴权的正常跳
    next()
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
